package com.xiaobawang.hundouluo.utils;

import android.content.Context;
import android.content.SharedPreferences;

public class SharedPreferencesUtil {
    //写数据
    public static void write(Context context, String fileName, String key, String value) {
        SharedPreferences prefs = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putString(key, value);
        editor.commit();
    }

    //读数据
    public static String read(Context context, String fileName, String key) {
        SharedPreferences prefs = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
        return prefs.getString(key, "false");
    }

    //删数据
    public static void clear(Context context, String fileName) {
        SharedPreferences prefs = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = prefs.edit();
        editor.clear();
        editor.commit();
    }
}
